<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "set_user_up".
 *
 * @property int $id
 * @property float $vip1 购买
 * @property float $vip3
 * @property int $vip3_2
 * @property float $r1 直推
 * @property float $r2
 * @property float $r3
 */
class SetUserUp extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'set_user_up';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['vip1', 'vip3', 'r1', 'r2', 'r3'], 'number'],
            [['vip3_2'], 'integer'],
            [['r1', 'r2', 'r3'], 'required'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'vip1' => 'Vip 1',
            'vip3' => 'Vip 3',
            'vip3_2' => 'Vip 3  2',
            'r1' => 'R 1',
            'r2' => 'R 2',
            'r3' => 'R 3',
        ];
    }

    public static function getLastOne()
    {
        $model = self::find()
            ->orderBy(['id' => SORT_DESC])
            ->one();

        if (!$model) {
            $model = new self();
        }

        return $model;
    }

    public static function saveData($data)
    {
        $model = self::getLastOne();

        if ($model->load(['SetUserUp' => $data]) && $model->save()) {
            return true;
        }
    }
}
